package smecta.client.print.controller;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ConcurrentHashMap;

@RestController
public class ConfirmWeightController {

    @FXML
    private TextField boxNum;
    @FXML
    private TextField canNum;
    @FXML
    private TextField weight;
    @FXML
    private Button confirmCloseButton;
    @FXML
    private Button confirmButton;
    ConcurrentHashMap<String, Object> cacheMap = ScpDataAcqController.cacheMap;

    public ScpDataAcqController scpDataAcqController = new ScpDataAcqController();
    @FXML
    private void initialize() {
        boxNum.setText(cacheMap.get("box").toString());
        canNum.setText(cacheMap.get("can").toString() );
        weight.setText((String) cacheMap.get("weight"));
    }

    @FXML
    private void handleConfirm() {
        String boxNumText = boxNum.getText();
        String canNumText = canNum.getText();
        String weightText = weight.getText();

        cacheMap.put("box",Integer.parseInt(boxNumText));
        cacheMap.put("can",Integer.parseInt(canNumText));
        cacheMap.put("weight",weightText);

        TextArea textArea = (TextArea) cacheMap.get("isUse");
        textArea.setText("");
        textArea.setText("定重");

        Stage stage = (Stage) confirmButton.getScene().getWindow();
        stage.close();
    }

    @FXML
    private void handleCancel() {
        // 关闭窗口
        Stage stage = (Stage) confirmCloseButton.getScene().getWindow();
        stage.close();
    }
}
